﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QLSVPT1h
{
    public partial class TimKiemHS : Form
    {
        public TimKiemHS()
        {
            InitializeComponent();
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        public SqlConnection con;
        private void Form1_Load(object sender, EventArgs e)
        {
            string connectionString = "Data Source=.;Initial Catalog=QLHS;Integrated Security=True";
            con = new SqlConnection(connectionString);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string a = textBox1.Text;
            string b = comboBox1.SelectedItem.ToString();
            if (b == "Mã Số")
                b = "MaHS";
            else
                if (b == "Ngày Sinh")
                    b = "NgaySinh";
                else
                    if (b == "Họ Tên")
                        b = "HoTen";
                    else
                        b = "MaLop";
            string c = comboBox2.SelectedItem.ToString();
            if (c == "Mã Số")
                c = "MaHS";
            else
                if (c == "Ngày Sinh")
                    c = "NgaySinh";
                else
                    if (c == "Họ Tên")
                        c = "HoTen";
                    else
                        c = "MaLop";
            string d = comboBox3.SelectedItem.ToString();
            if (d == "Giảm dần")
                d = "desc";
            else
                d = "asc";
            string commandString;
            commandString = "select * from HOCSINH where " + b + " = " + "N'" + a + "'" + " order by " + c + " " + d;
            con.Open();
            DataTable table = new DataTable();
            SqlDataAdapter data = new SqlDataAdapter(commandString, con);
            int row = data.Fill(table);
            progressBar1.Minimum = 0;
            progressBar1.Maximum = row;
            progressBar1.PerformStep();
            dataGridView1.DataSource = table;
            con.Close();
        }

        private void TimKiemHS_FormClosed(object sender, FormClosedEventArgs e)
        {
            Homepage_Form hp = new Homepage_Form();
            this.Visible = false;
            hp.Show();
        }
    }
}
